All files / app/api/icons/[size] route.tsx

100% Statements 29/29
80% Branches 4/5
100% Functions 1/1
100% Lines 29/29

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 381x     1x   1x   5x 5x 5x   5x 1x 1x   4x 4x 4x   4x 4x 4x 4x 4x 4x 4x 4x 4x 4x 5x 5x   5x 5x 5x 5x 5x  
import { ImageResponse } from 'next/og';
import { NextRequest } from 'next/server';
 
export const runtime = 'edge';
 
const VALID_SIZES = [72, 96, 128, 144, 152, 192, 384, 512];
 
export async function GET(request: NextRequest, { params }: { params: { size: string } }) {
  const sizeStr = params.size.replace('.png', '');
  const size = parseInt(sizeStr, 10);
 
  if (!VALID_SIZES.includes(size)) {
    return new Response('Invalid icon size', { status: 400 });
  }
 
  const isMaskable = request.nextUrl.searchParams.get('maskable') === 'true';
  const fontSize = Math.floor(size * 0.6);
  const borderRadius = Math.floor(size * 0.15);
 
  return new ImageResponse(
    <div
      style={{
        fontSize,
        background: 'linear-gradient(135deg, #7c3aed 0%, #06b6d4 100%)',
        width: '100%',
        height: '100%',
        display: 'flex',
        alignItems: 'center',
        justifyContent: 'center',
        borderRadius: isMaskable ? 0 : borderRadius,
      }}
    >
      <span style={{ color: 'white', fontWeight: 'bold' }}>P</span>
    </div>,
    { width: size, height: size }
  );
}